// BeamVars Library for PCMod (CLIENT)

PCBeam = {}
PCBeam.Storage = {}

function PCBeamRecieved( um )
	// Read out some core variables
	local id = um:ReadShort()
	local cnt = um:ReadShort()
	
	// Read the message into a table
	local temp = {}
	for i=1, cnt do
		local part = um:ReadString()
		local str = string.Explode( "#", part )
		local k = str[1]
		local v = str[2]
		local t = str[3]
		if (t == "number") then v = tonumber( v ) end
		if (t == "boolean") then v = tobool( v ) end
		temp[ k ] = v
	end
	
	// Throw the table into storage
	PCBeam.Storage[ id ] = temp
end
usermessage.Hook( "pcbeam", PCBeamRecieved )

function PCBeam:GetBeamValue( pc, tag, default )
	if ((!pc) || (!pc:IsValid())) then return 0 end
	local id = pc:EntIndex()
	if (!self.Storage[ id ]) then self.Storage[ id ] = {} end
	local val = self.Storage[ id ][ tag ]
	if (val) then return val end
	return default
end